<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" xmlns:t="http://myfaces.apache.org/tomahawk"
	template="/pages/template/main-layout.xhtml">

	<ui:define name="content">
		<t:saveState value="#{evokNodeBean.nodeList}" />
		<t:saveState value="#{evokNodeBean.nodeType}" />
		<t:saveState value="#{evokNodeBean.node}" />

		<h:panelGrid columns="3">
			<p:selectOneMenu converter="integerConverter" value="#{evokNodeBean.nodeType}"
				style="width:200px;">
				<f:selectItems value="#{sessionEnum['NodeType']}" var="ro" itemLabel="#{ro.name}"
					itemValue="#{ro.value}" />
			</p:selectOneMenu>

			<p:commandButton value="#{msgs.button_query}" icon="ui-icon-search"
				actionListener="#{evokNodeBean.queryNode}" update="nodeInfo,nodeList" />
		</h:panelGrid>
		<p />
		<p:panel header="Node Info" id="nodeInfo">
			<h:inputHidden value="#{evokNodeBean.node.id}" />
			<p:panelGrid columns="6" style="width:100%;">
				<h:outputLabel value="#{msgs.default_name}" />
				<p:inputText value="#{evokNodeBean.node.name}"
					style="width:90%;validator:checkNotNull(#{msgs.default_name});" />

				<h:outputLabel value="DISPLAY" />
				<p:inputText value="#{evokNodeBean.node.labelValue}"
					style="width:90%;validator:checkNotNull(DISPLAY);" />
					
				<h:outputLabel value="SORT" />
				<p:inputText value="#{evokNodeBean.node.sort}">
					<f:convertNumber integerOnly="true"/>
				</p:inputText>	

				<h:outputLabel value="DATA TYPE" />
				<p:selectOneMenu value="#{evokNodeBean.node.dataType}">
					<f:selectItems value="#{sessionEnum['NodeDataType']}" var="en" itemLabel="#{en.name}"
						itemValue="#{en.value}" />
				</p:selectOneMenu>

				<h:outputLabel value="ENUM" />
				<p:inputText value="#{evokNodeBean.node.enumName}" style="width:90%" />
				
				<h:outputLabel value="ROWS" />
				<p:inputText value="#{evokNodeBean.node.rows}" style="width:90%" >
					<f:convertNumber integerOnly="true"/>
				</p:inputText>
				
				<h:outputLabel value="REQUIRED" />
				<p:selectBooleanCheckbox value="#{evokNodeBean.node.required}" />

				<h:outputLabel value="MAX LENGTH" />
				<p:inputText value="#{evokNodeBean.node.maxLength}" style="width:90%" >
					<f:convertNumber integerOnly="true"/>
				</p:inputText>
				
				<h:outputLabel value="MAX FRACTION DIGITS" />
				<p:inputText value="#{evokNodeBean.node.maxFractionDigits}" style="width:90%" >
					<f:convertNumber integerOnly="true"/>
				</p:inputText>
				
				<h:outputLabel value="MAX INTEGER DIGITS" />
				<p:inputText value="#{evokNodeBean.node.maxIntegerDigits}" style="width:90%" >
					<f:convertNumber integerOnly="true"/>
				</p:inputText>
			</p:panelGrid>
			
			<f:facet name="footer">
				<p:commandButton onclick="return validator('nodeInfo');" value="#{msgs.button_submit}"
					icon="ui-icon-disk" update="nodeInfo,nodeList,:messages"
					actionListener="#{evokNodeBean.submitNode}" />
						&#160;
				<p:commandButton value="#{msgs.button_delete}" icon="ui-icon-trash"
					oncomplete="confirmDeleteNode.show()" />
						&#160;	
				<p:commandButton value="#{msgs.button_add}" icon="ui-icon-plus" update="nodeInfo"
					actionListener="#{evokNodeBean.resetNode}" />
			</f:facet>
		</p:panel>

		
		<p:dataTable id="nodeList" var="nd" value="#{evokNodeBean.nodeModel}" rowIndexVar="ri"
			selectionMode="single" widgetVar="wdgList" >
			<p:ajax event="rowSelect" listener="#{evokNodeBean.selectNodeRow}" update=":mainform:nodeInfo"/>
			
			<f:facet name="header">
				<p:commandButton value="reset" onstart="wdgList.clearSelection();" update="nodeList" style="float:left"/>
			</f:facet>      
			
			<p:column styleClass="width10" headerText="#{msgs.table_index}">
				<h:outputText value="#{ri+1}" />
			</p:column>
			
			<p:column headerText="TYPE" sortBy="#{nd.dataType}">
				<h:outputText value="#{nd.dataType}" converter="enumConverter" enumName="NodeDataType"/>
			</p:column>

			<p:column headerText="#{msgs.default_name}" sortBy="#{nd.name}">
				<h:outputText value="#{nd.name}" />
			</p:column>

			<p:column headerText="DISPLAY">
				<h:outputText value="#{nd.labelValue}" />
			</p:column>
			
			<p:column headerText="SORT">
				<h:outputText value="#{nd.sort}" />
			</p:column>
		</p:dataTable>
	</ui:define>
	
	<ui:define name="dialog">
		<h:panelGrid>
			<p:confirmDialog message="#{msgs.info_sure_delete}" width="200" showEffect="explode"
				hideEffect="explode" header="POZOR" severity="alert" widgetVar="confirmDeleteNode" modal="true">
				
				<p:commandButton value="DA" update=":mainform:nodeInfo,:mainform:nodeList,:messages"
					actionListener="#{evokNodeBean.deleteNode}" oncomplete="confirmDeleteNode.hide()" />
					
				<p:commandButton value="NE" onclick="confirmDeleteNode.hide()" type="button" />
			</p:confirmDialog>
		</h:panelGrid>
	</ui:define>
</ui:composition>
